package com.yingli.android_studying;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.yingli.android_studying.View.GridViewActivity;
import com.yingli.android_studying.View.ListViewActivity;
import com.yingli.android_studying.View.lmageViewActivity;

public class Main extends AppCompatActivity {
    //声明引用
    private Button mIVButton;
    private Button mLVButton;
    private Button mGVButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //获取控件对象
        mIVButton = (Button) findViewById(R.id.IVButton_Id);
        mGVButton = (Button) findViewById(R.id.GVButton_Id);
        mLVButton = (Button) findViewById(R.id.LVButton_Id);
        setlistener();
    }
    //设置监听器
    public void setlistener(){
        ButtonClickListener listener = new ButtonClickListener();
        mLVButton.setOnClickListener(listener);
        mGVButton.setOnClickListener(listener);
        mIVButton.setOnClickListener(listener);
    }
    //实现监听器接口
    class ButtonClickListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()){
                case R.id.GVButton_Id:
                    intent=new Intent(Main.this, GridViewActivity.class);
                    break;
                case R.id.IVButton_Id:
                    intent = new Intent(Main.this, lmageViewActivity.class);
                    break;
                case R.id.LVButton_Id:
                    intent =new Intent(Main.this, ListViewActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }
}